package service

import (
	"fmt"
	"net"
)

func process(conn net.Conn) {
	defer conn.Close()
	for {
		buf := make([]byte, 1024)
		n, err := conn.Read(buf)
		if err != nil {
			println("err:", err)
		} else {
			print(string(buf[:n]))
		}
	}
}

func main() {
	fmt.Println()
	listen, err := net.Listen("tcp", "127.0.01:8888") //连接器存活
	if err != nil {
		println("错误", err)
	}
	defer listen.Close()
	for {
		//连接为每个客户端提供连接允许
		conn, err := listen.Accept()
		if err != nil {
			println(err)
			return
		} else {
			println("Accept()", conn)
		}
		go process(conn)
	}

}
